package com.warrior.gatherweb.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Slf4j
public class DateUtils {
	
    public static String addDay(int num, String formatString) {
        formatString = Strings.isBlank(formatString) ? CommonStatus.CONSTANT_DATETIME_FORMAT : formatString;
        SimpleDateFormat format = new SimpleDateFormat(formatString);
        try {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DATE, num);
            Date date = c.getTime();
            return format.format(date);
        }
        catch (Exception e){
        	log.error("时间解析异常");
            return null;
        }
    }

    public static String getCurrentDate(Date date, String format){
        date = date == null ? new Date() : date;
        format = Strings.isBlank(format) ? CommonStatus.CONSTANT_DATETIME_FORMAT : format;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }


    
}
